package com.druid;

import com.alibaba.druid.filter.config.ConfigFilter;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.util.DruidPasswordCallback;

import java.util.Properties;

public class DbPasswordCallback extends DruidPasswordCallback {
    private static final long serialVersionUID = 1L;
    private static final String PASSWORD_KEY = "password";
    private String url;
    private Properties properties;
    private com.druid.SecretRequest secretRequest;
    DruidDataSource d;

    public com.druid.SecretRequest getSecretRequest() {
        return this.secretRequest;
    }

    public void setSecretRequest(com.druid.SecretRequest secretRequest) {
        this.secretRequest = secretRequest;
    }

    public DbPasswordCallback(String prompt, boolean echoOn) {
        super(prompt, echoOn);
    }

    public DbPasswordCallback() {
        this("db pwd", true);
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Properties getProperties() {
        return this.properties;
    }

    public void setProperties(Properties properties) {
        String configFile = properties.getProperty("config.file");
        this.properties = new ConfigFilter().loadConfig(configFile);
        String pwd = this.properties.getProperty("password");
        try {
            setPassword("root".toCharArray());
        } catch (Exception e) {
            e.printStackTrace();
            setPassword(pwd.toCharArray());
        }
    }
}